package cn.edu.nwsuaf.examcenter.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.edu.nwsuaf.examcenter.service.StudentService;
import cn.edu.nwsuaf.examcenter.model.PageModel;
import cn.edu.nwsuaf.examcenter.model.StudentScoreModel;
import cn.edu.nwsuaf.examcenter.service.CourceEmployeeService;
import cn.edu.nwsuaf.examcenter.service.ExamPaperService;
import cn.edu.nwsuaf.examcenter.service.StudentCommonScoreService;
import cn.edu.nwsuaf.examcenter.service.StudentCourceScoreService;
import cn.edu.nwsuaf.examcenter.service.StudentExamScoreService;

@Controller
@RequestMapping(value="/studentCourceScore")
public class StudentCourceScoreController {
	@Resource(name="studentService")
	private StudentService studentService;
	
	@Resource(name="courceEmployeeService")
	private CourceEmployeeService courceEmployeeService;
	
	@Resource(name="studentCommonScoreService")
	private StudentCommonScoreService studentCommonScoreService;
	
	@Resource(name="studentCourceScoreService")
	private StudentCourceScoreService studentCourceScoreService;
	
	@Resource(name="studentExamScoreService")
	private StudentExamScoreService studentExamScoreService;
	
	@Resource(name="examPaperService")
	private ExamPaperService examPaperService;
	@RequestMapping(value="/loadStudentList")
	public String loadStudentList(ModelMap modelMap){
		studentService.loadStudent(modelMap);
		return "exam/student-cource-score-list";
	}
	
	@RequestMapping(value="/loadStudentCourceScore/{studentNo}")
	public String loadStudentCourceScore(@PathVariable String studentNo, ModelMap modelMap){
		List<StudentScoreModel> studentScoreModel = new ArrayList<>();
		List<String> courceList = new ArrayList<>();
		List<String> examList = new ArrayList<>();
		
		
		//1、获取到班级信息
		String classNo = studentService.getMyClassNo(studentNo);
		//2、获取到班级的课程信息
		courceEmployeeService.getMyCource(classNo, courceList, studentScoreModel);
		//3、通过课程信息查询平时成绩
		studentCommonScoreService.getStudentCommonScore(studentNo, courceList, studentScoreModel);
		//4、通过课程信息查询试卷信息，在通过试卷信息查询试卷成绩
		examPaperService.loadExamList(examList, courceList);
		studentExamScoreService.getStudentExamScore(studentNo, examList, studentScoreModel);
		//5、通过课程信息查询综合成绩/
		studentCourceScoreService.getStudentCourceScore(studentNo, courceList, studentScoreModel);
		
		PageModel<StudentScoreModel> pageModel = new PageModel<>();
		pageModel.setTotalrows(studentScoreModel.size());
		pageModel.setList(studentScoreModel);
		
		modelMap.addAttribute("pageModel",pageModel);
		return "exam/student-cource-score";
	}
}
